import axios from 'axios'
import { Toast } from 'vant'

const service = axios.create({
  baseURL: 'https://www.heytap.com/cn/oapi',
  timeout: 10000,
  withCredentials: true, // 允许携带cookie
})

service.interceptors.request.use(config => {
  console.log('请求拦截')
  Toast.loading({
    message: '加载中......',
    duration: 0,
  })

  return config
})

service.interceptors.response.use(response => {
  console.log('响应拦截')
  Toast.clear()
  // if (response.status === 200) {
  //   const { code, data } = response.data
  //   if (code === 200) {
  //     return data
  //   }
  // }
  return response.data
  // const err = new Error('请求error')
  // err.error = response
  // return Promise.reject(err)
})

export default service
